package com.zian.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;

import com.zian.properties.AliPayProperties;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Description:
 * @Version: V1.0
 */
@Configuration
@Data
public class AlipayConfig {

    @Autowired
    private AliPayProperties payProperties;

    public Config config() {
        Config config = new Config();
        config.protocol = payProperties.getProtocol();
        config.gatewayHost = payProperties.getGatewayHost();
        config.signType = payProperties.getSignType();
        config.appId = payProperties.getAppId();
        config.merchantPrivateKey = payProperties.getMerchantPrivateKey();
        config.alipayPublicKey = payProperties.getAlipayPublicKey();
        //可设置异步通知接收服务地址（可选）
        config.notifyUrl = payProperties.getNotifyUrl();
        config.encryptKey = "";
        return config;
    }


    @PostConstruct
    public void init(){
        Factory.setOptions(config());
    }
}
